home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr48
/
pas_0593.zip
/
ALPHA.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-05-30
|
6KB
|
166 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 452 of 460
From : Justin Marquez 1:106/100.1 20 May 93 20:41
To : Steven Morales
Subj : Port[] - ?
────────────────────────────────────────────────────────────────────────────────
SM> I've see it used for keypress info and stuff... How do I use PORT[] in
SM> general. PORT[80] is used for when a key is pressed. Whatelse can I do
SM> with it? Please help me - thanks - I also need help with TSRs too...
It can also be used to access non-standard added-in cards. For example, ALPHA
PRODUCTS makes a whole family of data-gathering devices that attach to PC's via
an "Alpha Bus" card. (They make bus cards for many different little computers -
same end device cards, all adapted to different PC's via a BUS card in or
attached to the PC.) I have one of them that I have tinkered with some, the
AD-142 for 8-bit analog-to-digital conversion. Here's some sample code. Only
the part for the AD-142 has been tested. The other stuff compiles OK, but I
don't have the other cards (yet) to play with.}
UNIT ALPHA;
{ Contains the routines to access the APLHA Products line of
A-BUS Data Collection and control system I/O cards }
INTERFACE
USES DOS,CRT,Printer;
TYPE AD142 = record
{ All 8 channels numbers + a time & date stamp when read }
Channel : Array [0..7] of BYTE;
end;
LI157 = record
Read_Value : byte;
Channel : Array [0..7] of Boolean; { TRUE = SET or 1 }
end;
CONST
Adapter_Address = 512; { PC adapter installed at this Port
Remember to ADD the CARD ADDRESS, too }
Card_Address = 0; { These two are factory defaults }
VAR
Data_Point : AD142;
{ copy just the HEADERS for all the procs and functions called by this
unit into this space }
FUNCTION Make_A_Stamp : LongInt; { time/date stamp for data logging }
FUNCTION POWER2 (n:Integer): Integer;
PROCEDURE Read_LI_157 (Card_Number:Integer; VAR Reading : LI157);
PROCEDURE DA_147_Output (Card_Number,Channel_Number,Out_Value: Integer);
Function Read_A_Channel_FA154( Card_Number,Channel_Number : integer): Integer;
PROCEDURE Read_AD142 ( Card_Number : Integer; VAR Reading: AD142);
PROCEDURE Show_Raw_Readings(Reading: AD142); { Numbers as read in at the port }
IMPLEMENTATION
{ the actual procedures and functions go in here }
FUNCTION Make_A_Stamp : LongInt; { time/date stamp for data logging }
Var
Date_Time : DateTime; { record for PackTime to munge on }
Day_Of_Week,
Sec100s : word; { dummies for GetDate and GetTime }
Packed_Date_And_Time : LongInt;
Begin
Packed_Date_And_Time := 0; { always init the value to SOMETHING... }
FillChar(Date_Time,SizeOf(Date_Time),#0);
WITH Date_Time DO
begin
GetDate(Year,Month,Day,Day_Of_Week);
GetTime(Hour,Min,Sec,Sec100s);
PackTime(Date_Time,Packed_Date_And_Time);
Make_A_Stamp := Packed_Date_And_Time
end
End; { of Make_A_Stamp }
FUNCTION POWER2 (n:Integer): Integer;
Var i : integer;
Begin
i := 1;
While n > 0 DO
begin
i := i*2;
dec(n);
end;
POWER2 := i
End;
PROCEDURE Read_LI_157 (Card_Number:Integer; VAR Reading : LI157);
Var i,Port_At : Integer;
Begin
FillChar(Reading,SizeOf(Reading),#0);
{ usually 512 0 to 64 }
Port_At := Adapter_Address + Card_Number;
With Reading DO
begin
Read_Value := PORT[Port_At];
For i := 0 to 7 DO
If ( ((Read_Value AND Power2(i)) = 1) ) Then Channel[i] := TRUE;
end
End;
PROCEDURE DA_147_Output (Card_Number,Channel_Number,Out_Value: Integer);
{ Compiles, but is Untested !! }
Var Port_At: integer;
Begin
{ usually 512 0 to 64 0 to 3 }
Port_At := Adapter_Address + Card_Number + Channel_Number;
PORT[Port_At] := Out_Value;
delay(1);
End; { of DA-147 Output routine }
Function Read_A_Channel_FA154( Card_Number,Channel_Number : integer): Integer;
{ Compiles OK but is UNTESTED with a real FA-154 card! }
{ This is for an ALPHA Products 12-bit Fast A/D Card, FA-154
The values returned from it range from 0 - 4095
Conversion time is 10 microseconds.(0.000010 second) }
Var n, Hi, Lo, P0, P1 : Integer;
Begin
P0 := Adapter_Address + Card_Number; { Compute Card Base Port Address}
P1 := P0 +1; { Second Port for Hi value }
n := 0; { Initialize - looks good to do it }
Port[P0] := Channel_Number; { Tell the card which channel }
n := Port[P0]; { Dummy Reading to start conversion }
Delay(1); { 0.001 sec. wait, may not need }
Hi := Port[P1]; { Read High address first }
Lo := Port[P0]; { Read Low Address next }
n := (Hi*256)+Lo; { Value will be between 0 and 4095 }
Read_A_Channel_FA154 := n;
End; { of read a channel on the FA154 }
FUNCTION Read_A_Channel_AD142 (Card_Number,Channel_Number :integer):byte;
{ Tested }
{ This is for an 8-bit A/D Card, readings are 0 - 255, 160 microsecond
conversion time. ALPHA Products AD142 }
Var
n,
Port_At : integer;
Begin
n := 0;
Port_At := Adapter_Address + Card_Number; { Compute Port Address}
Port[Port_At] := Channel_Number; { Tell the card which channel }
delay(5); { wait 5 ms for conversion }
n := Port[Port_At]; { Read data in }
Read_A_Channel_AD142 := n;
End; { of read one channel }
PROCEDURE Read_AD142 ( Card_Number : Integer; VAR Reading: AD142);
{Tested}
Var Channel_Number, n, Port_At : Integer;
Begin
Port_At := Adapter_Address + Card_Number;{ Compute Port Address}
FillChar(Reading,SizeOf(Reading),#0); { Clear the record first }
WITH Reading DO
begin
for Channel_Number := 0 to 7 DO
Channel[Channel_Number] :=
Read_A_Channel_AD142(Card_Number,Channel_Number);
end { of WITH... }
End; { of Read_AD142 }
PROCEDURE Show_Raw_Readings(Reading: AD142); { Numbers as read in at the port }
{ tested }
Var n : integer;
Begin
For n := 0 to 7 DO
Write(Reading.Channel[n]:6);
End; { of Show_Raw_Readings }
END.